<template>
    <div class="codeedit">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="600px"
                :close-on-click-modal="false"
                @close="close"
        >
            <div :element-loading-text="elementLoadingText" v-loading="listLoading">
                <el-form ref="form" :model="form" label-width="120px">
                    <el-form-item label="活码数量" prop="num" :required="true">
                        <el-input v-model.trim="form.num" autocomplete="off" placeholder="请输入活码数量"></el-input>
                        <div class="yb_margin lh16">请输入需要创建的二维码数量，活码生成后请尽量不要删除。</div>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="medium" @click="close">取 消</el-button>
                    <el-button size="medium" type="primary" @click="save">确 定</el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {establishCode} from "@/api/instore";

    export default {
        name: "meteriaSave",
        created() {
        },
        data() {
            return {
                form: {
                    id: '',
                    num: '',
                },
                title: "",
                dialogFormVisible: false,
                listLoading: false,
                elementLoadingText: "正在新增数据，请稍等...",
            }
        },
        components: {},
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "新增活码";
                } else {
                    this.title = "编辑";
                    this.getSaveTable(row.id)
                    // this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            // async getSaveTable(id) {
            //     const {data} = await getSaveTable({id,});
            //     this.form = Object.assign({}, data);
            // },
            setStoreId(storeId){
                this.form.storeId = storeId
            },
            close() {
                this.$refs["form"].resetFields();
                this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            save() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.listLoading = true
                        const {msg} = await establishCode(this.form);
                        this.$baseMessage(msg, "success");
                        this.$emit("fetchData");
                        this.listLoading = false
                        this.close();
                    } else {
                        return false;
                    }
                });
            },
        }
    };
</script>
<style lang="scss">
    .codeedit{
        .dialog-footer{
            text-align: right;
        }
    }
</style>

